<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/21
 * Time: 11:14
 */

namespace app\admin\controller;
use app\admin\model\Base;
use think\Controller;
use think\Db;
use think\Request;

class Order extends Common
{
    public $obj = "";
    public $table = "order";
    public $date = "";
    public $go = "order";

    public function __initialize()
    {
        parent::__initialize();

    }

    public function show()
    {


        $list = Db::table('order')->order("id","desc")->paginate(3);
        $page=$list->render();
        // 模板变量赋值
        $this->assign('list', $list);
        $this->assign('page',$page);
        // 渲染模板输出
        return $this->fetch($this->go . '/show');
    }


//添加数据页面
    public function add()
    {

        $list = Db::table('userinfo')->select();
        $this->assign('list', $list);
        $goods = Db::table('goods')->select();
        $this->assign('goods', $goods);
        return $this->fetch();
    }

    //添加数据信息
    public function addm()
    {
        $object = new Base();
        $table = $this->table;
        $date = $_POST;
        $date=Request::instance()->post();
        $data=date("Y-m-d",time());
        $arr=explode("-",$data);
        $date['year']=$arr['0'];
        $date['month']=$arr['1'];
        $date['day']=$arr['2'];
         //var_dump($date);die;
        $obj=$object->add($table,$date);
        //var_dump($date);die;
        if ($obj) {
            $this->success('添加成功', url('Order/show'));
        } else {
            $this->error('添加失败');
        }
    }


//信息删除
    public function dels()
    {
        $obj=new Base();
        $id=input('id');
        //var_dump($id);
        $table=$this->table;
        $rs=$obj->del($table,$id);
        if($rs){
            $this->success('删除成功', url('Order/show'));
        }else {
            $this->error('删除失败');
        }
    }

}